package com.kd.juhaowan.ui.holder;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;


import com.kd.juhaowan.R;
import com.kd.juhaowan.http.model.GameGiftModel;
import com.kd.juhaowan.http.model.GiftModel;
import com.kd.juhaowan.ui.adapter.BaseRecyclerViewAdapter;
import com.kd.juhaowan.ui.adapter.BaseViewHolder;
import com.kd.juhaowan.ui.listener.OnGiftReciveListener;
import com.kd.juhaowan.ui.listener.OnItemDianzanListener;

import butterknife.BindView;

public class GameGiftViewHolder extends BaseViewHolder implements OnItemDianzanListener {



    @BindView(R.id.gift_item_name)
    TextView nameView;
    @BindView(R.id.gift_item_listView)
    RecyclerView listView;

    private BaseRecyclerViewAdapter<GameGiftChildViewHolder, GiftModel> giftAdapter;
    private OnGiftReciveListener mListener;




    public GameGiftViewHolder(@NonNull View itemView, OnGiftReciveListener listener) {
        super(itemView);
        mListener = listener;

    }



    @SuppressLint("ResourceType")
    public void setDate(GameGiftModel model){
        nameView.setText(model.getName());
        giftAdapter = new BaseRecyclerViewAdapter<GameGiftChildViewHolder, GiftModel>() {
            @NonNull
            @Override
            public GameGiftChildViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                LayoutInflater inflater = LayoutInflater.from(parent.getContext());
                View view = inflater.inflate(R.layout.item_game_djq, parent, false);
                GameGiftChildViewHolder holder=new GameGiftChildViewHolder(view);
                holder.setOnItemClickListener(getOnItemClickListener());
                return  holder;

            }

            @Override
            public void onBindViewHolder(@NonNull GameGiftChildViewHolder holder, int position) {
                holder.setDate(getItem(position),position ==getItemCount()-1);

            }
        };
        giftAdapter.setOnItemClickListener(this);
//        List<GiftModel2> list = new ArrayList<>();
//        list.addAll(model.getBills());
//        list.addAll(model.getBills());
//        list.addAll(model.getBills());
//        list.addAll(model.getBills());
//        list.addAll(model.getBills());
        giftAdapter.resetAdapterData(model.getGiftpackList());
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
        layoutManager.setOrientation(RecyclerView.VERTICAL);

        listView.setLayoutManager(layoutManager);
        listView.setAdapter(giftAdapter);


    }

    @Override
    public void onItemClick(RecyclerView.ViewHolder viewHolder, View view, int position) {

    }

    @Override
    public void onItemDianzanClick(BaseViewHolder viewHolder,int position) {
        GiftModel model = giftAdapter.getItem(position);
       if(mListener!=null){
           mListener.onRecive(model);
       }
//        ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(CLIPBOARD_SERVICE);
//        if(clipboard != null){
//            ClipData clip = ClipData.newPlainText("text", model.getCode());
//            clipboard.setPrimaryClip(clip);
//            Toast.makeText(getContext(),"已复制到剪贴板",Toast.LENGTH_SHORT).show();
//        }
    }
}
